// 799. 香槟塔
/**
 * @param {number} poured
 * @param {number} query_row
 * @param {number} query_glass
 * @return {number}
 */
 var champagneTower = function(poured, query_row, query_glass) {
    const map = [];
    let topUpPoured = Math.pow(2, query_row) - 1;

    console.log('topUpPoured', topUpPoured);
    // if (poured >= topUpPoured) {
    //     return 1;
    // }

    for(let b = 0; b < query_row + 10; b ++) { map.push(new Array(b + 1).fill(0)) }

    map[0][0] = poured;

    for(let i = 0; i < query_row; i++) {
        for(let j = 0; j < map[i].length; j++) {
            let temp = map[i][j] - 1;
            if (temp < 0) continue;
            map[i][j] = 1;
            map[i+1][j] += temp / 2;
            map[i+1][j+1] += temp / 2;
        }
    }


    console.log("%c Line:35 🍰", "color:#33a5ff", map, topUpPoured);
    
    return Math.min(map[query_row][query_glass], 1);
};



console.log("%c Line:7 🥝", "color:#33a5ff", champagneTower(2, 1, 1));